package com.xju.common.utils;

import java.util.Date;
import java.util.List;

public class PageInfo<T> {
    private int pageNo;
    private int pageSize;
    private int totalPage;
    private int count;
    private List<T> records;

    private int current;
    private int next;
    private int pre;
    private boolean hasNext;
    private boolean hasPre;
    private boolean last;
    private boolean first;
    private String updateTime;

    @Override
    public String toString() {
        return "PageInfo{" +
                "pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", totalPage=" + totalPage +
                ", count=" + count +
                ", records=" + records +
                ", current=" + current +
                ", next=" + next +
                ", pre=" + pre +
                ", hasNext=" + hasNext +
                ", hasPre=" + hasPre +
                ", last=" + last +
                ", first=" + first +
                ", updateTime='" + updateTime + '\'' +
                '}';
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    public void setCurrent(int current) {
        this.current = current;
    }

    public void setNext(int next) {
        this.next = next;
    }

    public void setPre(int pre) {
        this.pre = pre;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    public void setHasPre(boolean hasPre) {
        this.hasPre = hasPre;
    }

    public void setLast(boolean last) {
        this.last = last;
    }

    public void setFirst(boolean first) {
        this.first = first;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public PageInfo(int pageNo, int pageSize, int totalPage, int count, List<T> records, int current, int next, int pre, boolean hasNext, boolean hasPre, boolean last, boolean first, String updateTime) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalPage = totalPage;
        this.count = count;
        this.records = records;
        this.current = current;
        this.next = next;
        this.pre = pre;
        this.hasNext = hasNext;
        this.hasPre = hasPre;
        this.last = last;
        this.first = first;
        this.updateTime = updateTime;
    }

    public PageInfo(int pageNo, int pageSize, int count, List<T> records) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.count = count;
        this.records = records;
        totalPage = (count/pageSize) + (count%pageSize==0?0:1);

        this.current =pageNo;
        this.hasNext = (pageNo!=totalPage);
        this.hasPre = (pageNo!=1);

        this.next = this.current + (hasNext?1:0);
        this.pre = this.current - (hasPre?1:0);
        this.last = !hasNext;
        this.first = !hasPre;
    }

    public int getPageNo() {
        return pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public int getCount() {
        return count;
    }

    public List<T> getRecords() {
        return records;
    }

    public int getCurrent() {
        return current;
    }

    public int getNext() {
        return next;
    }

    public int getPre() {
        return pre;
    }

    public boolean isHasNext() {
        return hasNext;
    }

    public boolean isHasPre() {
        return hasPre;
    }

    public boolean isLast() {
        return last;
    }

    public boolean isFirst() {
        return first;
    }
}
